//
// Created by root on 2/25/18.
//

#include "refactorengine.h"

#include "../engine/common.h"

// {dump code to {"newcode.fn"}}
String dumpcode(Statement *st) {
    //todo
    //printf("todo dumpcode ...");

    return NULL;
}

/*
void dumpcode(Statement *st) {
	char *fileName = get_file_from_statement(st);

	Queue *mappings;
	for (Mapping m : mappings) {
		String func = m->sourceFunc;
		if (func contains "::") {
			String className = func.split("::")[0];
			String methodName = func.split("::")[1];
			put map (className, methodName + source);
		}
	}

	for (className name : map) {
		get properties of name;
		get methods from map;
		write_log_file(fileName, FILE_MAX_SIZE, buffer, strlen(buffer));
	}
}
*/

// {dump class {""} to {"newcode.fn"}}
String dumpclass(Statement *st1, Statement *st2) {
    //todo
    //printf("todo dumpclass ...");

    return NULL;
}

//dumphierarchy
String dumphier(Statement *st) {
    //todo
    //printf("todo dumphierarchy ...");

    return NULL;
}


/*

static Mapping* create_mapping(String method, Statement* signature) {
    Mapping *mapping = alloc_mapping();
    mapping->sys = NULL;
    mapping->isMacro = FALSE;
    mapping->functionName = method;
    mapping->sourceStatement = signature;
    String targetString = init_string();
    targetString = dyna_strcat(targetString, "{(");
    targetString = dyna_strcat(targetString, method);
    targetString = dyna_strcat(targetString, " ");
    targetString = dyna_strcat(targetString, target(signature));
    targetString = dyna_strcat(targetString, ")}");
    //mapping->targetStatement = parse("{(method TARGET[{signature}])}"); //??
    mapping->targetStatement = parse(targetString);
    return mapping;
}

static void add_method_include_sub_classes(TreeNode* classNode, String method, Statement* signature) {
    if (classNode == NULL) {
        return;
    }
    if (classNode->data == NULL) {
        classNode->data = hashmap_new();
    }
    Map classElements = (Map)(classNode->data);
    ClassElement* classElement = alloc_class_element();
    classElement->type = METHOD;
    classElement->element = create_mapping(method, signature);
    hashmap_put(classElements, method, classElement);

    Queue* subClasses = classNode->children;
    QueueNode* queueNode = NULL;
    TreeNode* subClassNode = NULL;
    if (!is_queue_empty(subClasses)) {
        queueNode = subClasses->head;
        while (queueNode != NULL) {
            subClassNode = (TreeNode*)queueNode->element;
            add_method_include_sub_classes(subClassNode, method, signature);
            queueNode = queueNode->next;
        }
    }
}

String addmethod(Statement *s1, Statement *s2) {
	String method = extract(s1);
    add_method_include_sub_classes(globalFunny->classNode, method, s2);
	return NULL;
}
*/

